
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3.2 String & Array · gitbook电子书</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="date.html" />
    
    
    <link rel="prev" href="Date类型.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    前言
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" data-path="../使用/使用.html">
            
                <a href="../使用/使用.html">
            
                    
                    md语法 & gitbook使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../面试题/面试题.html">
            
                <a href="../面试题/面试题.html">
            
                    
                    面试题
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../面试题/html.html">
            
                <a href="../面试题/html.html">
            
                    
                    HTML
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../面试题/css.html">
            
                <a href="../面试题/css.html">
            
                    
                    CSS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../面试题/js.html">
            
                <a href="../面试题/js.html">
            
                    
                    JavaScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../面试题/vue.html">
            
                <a href="../面试题/vue.html">
            
                    
                    Vue
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../面试题/小程序.html">
            
                <a href="../面试题/小程序.html">
            
                    
                    小程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../面试题/编程题.html">
            
                <a href="../面试题/编程题.html">
            
                    
                    编程题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../html/">
            
                <a href="../html/">
            
                    
                    1. HTML
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../html/1.常用标签.html">
            
                <a href="../html/1.常用标签.html">
            
                    
                    1.1 常用标签
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../html/2.列表.html">
            
                <a href="../html/2.列表.html">
            
                    
                    1.2 列表
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../html/3.表单.html">
            
                <a href="../html/3.表单.html">
            
                    
                    1.3 表单属性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../html/4.音频&视频.html">
            
                <a href="../html/4.音频&视频.html">
            
                    
                    1.4 ifame & audio & video
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../css/">
            
                <a href="../css/">
            
                    
                    2. CSS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../css/1.选择器.html">
            
                <a href="../css/1.选择器.html">
            
                    
                    2.1 选择器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../css/2.字体样式.html">
            
                <a href="../css/2.字体样式.html">
            
                    
                    2.2 字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../css/3.背景.html">
            
                <a href="../css/3.背景.html">
            
                    
                    2.3 背景
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../css/4.盒子模型.html">
            
                <a href="../css/4.盒子模型.html">
            
                    
                    2.4 盒子模型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../css/5.浮动.html">
            
                <a href="../css/5.浮动.html">
            
                    
                    2.5 浮动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../css/6.定位和渐变.html">
            
                <a href="../css/6.定位和渐变.html">
            
                    
                    2.6 定位 & 渐变
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../css/7.过渡&变形.html">
            
                <a href="../css/7.过渡&变形.html">
            
                    
                    2.7 过渡 & 变形
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../css/8.动画.html">
            
                <a href="../css/8.动画.html">
            
                    
                    2.8 动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../css/9.滤镜.html">
            
                <a href="../css/9.滤镜.html">
            
                    
                    2.9 滤镜
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../css/10.布局.html">
            
                <a href="../css/10.布局.html">
            
                    
                    2.10 布局
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="./">
            
                <a href="./">
            
                    
                    3. JS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="数据类型.html">
            
                <a href="数据类型.html">
            
                    
                    3.1 数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="语句.html">
            
                <a href="语句.html">
            
                    
                    操作符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="操作符.html">
            
                <a href="操作符.html">
            
                    
                    语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="基本类型和引用类型的值.html">
            
                <a href="基本类型和引用类型的值.html">
            
                    
                    基本类型和引用类型的值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="执行环境及作用域.html">
            
                <a href="执行环境及作用域.html">
            
                    
                    执行环境及作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="垃圾收集.html">
            
                <a href="垃圾收集.html">
            
                    
                    垃圾收集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="Object类型.html">
            
                <a href="Object类型.html">
            
                    
                    Object类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.9" data-path="Array类型.html">
            
                <a href="Array类型.html">
            
                    
                    Array类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.10" data-path="Date类型.html">
            
                <a href="Date类型.html">
            
                    
                    Date类型
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.5.11" data-path="string&array.html">
            
                <a href="string&array.html">
            
                    
                    3.2 String & Array
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.12" data-path="date.html">
            
                <a href="date.html">
            
                    
                    3.3 Date类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.13" data-path="正则表达式.html">
            
                <a href="正则表达式.html">
            
                    
                    3.4 RegExp类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.14" data-path="global&math.html">
            
                <a href="global&math.html">
            
                    
                    3.5 Global对象 & Math对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.15" data-path="变量&作用域&垃圾收集.html">
            
                <a href="变量&作用域&垃圾收集.html">
            
                    
                    3.6 变量 & 作用域 & 垃圾收集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.16" data-path="流程控制&函数.html">
            
                <a href="流程控制&函数.html">
            
                    
                    3.7 流程控制 & 函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.17" data-path="面向对象.html">
            
                <a href="面向对象.html">
            
                    
                    3.8 面向对象的程序设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.18" data-path="递归&冒泡&快速.html">
            
                <a href="递归&冒泡&快速.html">
            
                    
                    3.9 递归 & 冒泡 & 快速
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.19" data-path="定时器&防抖&节流.html">
            
                <a href="定时器&防抖&节流.html">
            
                    
                    3.10 定时器\防抖\节流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.20" data-path="DOM获取&DOM操作.html">
            
                <a href="DOM获取&DOM操作.html">
            
                    
                    3.11 DOM获取 & DOM操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.21" data-path="键盘事件&鼠标事件.html">
            
                <a href="键盘事件&鼠标事件.html">
            
                    
                    3.12 键盘事件 & 鼠标事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.22" data-path="事件冒泡&事件代理&事件绑定.html">
            
                <a href="事件冒泡&事件代理&事件绑定.html">
            
                    
                    3.13 事件冒泡\代理\绑定
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.23" data-path="this指向.html">
            
                <a href="this指向.html">
            
                    
                    3.14 this指向
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.24" data-path="Ajax&跨域.html">
            
                <a href="Ajax&跨域.html">
            
                    
                    3.15 Ajax & 跨域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.25" data-path="Bom.html">
            
                <a href="Bom.html">
            
                    
                    3.16 BOM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.26" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    3.17 ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.27" data-path="js实例.html">
            
                <a href="js实例.html">
            
                    
                    3.18 js实例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../vue/">
            
                <a href="../vue/">
            
                    
                    4. Vue
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../vue/1.基础.html">
            
                <a href="../vue/1.基础.html">
            
                    
                    4.1 基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../vue/2.生命周期.html">
            
                <a href="../vue/2.生命周期.html">
            
                    
                    4.2 生命周期
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../vue/3.vuex.html">
            
                <a href="../vue/3.vuex.html">
            
                    
                    4.3 vuex
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../vue/4.原理.html">
            
                <a href="../vue/4.原理.html">
            
                    
                    4.4 深入响应式原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../vue/5.组件.html">
            
                <a href="../vue/5.组件.html">
            
                    
                    4.5 组件进阶
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../vue/6.规模化.html">
            
                <a href="../vue/6.规模化.html">
            
                    
                    4.6 规模化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../vue/7.过渡&动画.html">
            
                <a href="../vue/7.过渡&动画.html">
            
                    
                    4.7 过渡 & 动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="../vue/8.可复用性&组合.html">
            
                <a href="../vue/8.可复用性&组合.html">
            
                    
                    4.8 可复用性 & 组合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="../vue/9.工具.html">
            
                <a href="../vue/9.工具.html">
            
                    
                    4.9 工具
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../Node/">
            
                <a href="../Node/">
            
                    
                    5. Node
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../插件/">
            
                <a href="../插件/">
            
                    
                    插件
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3.2 String & Array</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="string&#x65B9;&#x6CD5;">String&#x65B9;&#x6CD5;</h1>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> num1 =<span class="hljs-string">&quot;hello js&quot;</span>;
</code></pre>
<h5 id="1-&#x5B57;&#x7B26;&#x65B9;&#x6CD5;-charat--charcodeat--fromcharcode-">1. &#x5B57;&#x7B26;&#x65B9;&#x6CD5; charAt() &amp; charCodeAt() &amp; fromCharCode( )</h5>
<pre><code class="lang-js">    <span class="hljs-built_in">console</span>.log(num1[<span class="hljs-number">0</span>]);   
    <span class="hljs-comment">// 1.charAt() &#x8FD4;&#x56DE;&#x4E0B;&#x6807;&#x5BF9;&#x5E94;&#x7684;&#x5B57;&#x7B26;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;charAt&quot;</span>,num1.charAt(<span class="hljs-number">3</span>));
    <span class="hljs-comment">// 2.charCodeAt() &#x8FD4;&#x56DE;10&#x8FDB;&#x5236;&#x7684;Unicode&#x7F16;&#x7801;&#xFF08;16&#x8FDB;&#x5236;&#xFF09;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;charCodeAt&quot;</span>,num1.charCodeAt(<span class="hljs-number">0</span>));
    <span class="hljs-comment">// 3.fromCharAt() &#x8FD4;&#x56DE;10&#x8FDB;&#x5236;Unicode&#x7F16;&#x7801;&#x5BF9;&#x5E94;&#x7684;&#x5B57;&#x7B26;&#x4E32;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">String</span>.fromCharCode(<span class="hljs-number">104</span>,<span class="hljs-number">101</span>));
</code></pre>
<h5 id="2-&#x5B57;&#x7B26;&#x4E32;&#x64CD;&#x4F5C;&#x65B9;&#x6CD5;-concat--slice--substr--substring">2. &#x5B57;&#x7B26;&#x4E32;&#x64CD;&#x4F5C;&#x65B9;&#x6CD5; concat() &amp; slice() &amp; substr() &amp; substring()</h5>
<pre><code class="lang-js">    <span class="hljs-comment">// 1.concat() &#x8FD4;&#x56DE;&#x65B0;&#x5B57;&#x7B26;&#x4E32; &#x53EF;&#x4E00;&#x6B21;&#x6027;&#x6DFB;&#x52A0;&#x591A;&#x4E2A;</span>
    <span class="hljs-built_in">console</span>.log(num1.concat(<span class="hljs-string">&quot;&#xFF01;&quot;</span>,<span class="hljs-string">&quot;&#xFF1F;&quot;</span>));
    <span class="hljs-built_in">console</span>.log(num1+<span class="hljs-string">&quot;&#xFF01;&quot;</span>);

    <span class="hljs-comment">// 2.slice&#xFF08;&#x5F00;&#x59CB;&#xFF0C;&#x7ED3;&#x675F;&#xFF09; &#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x7247;&#x6BB5;</span>
    <span class="hljs-comment">// &#x5F00;&#x59CB;&#x4F4D;&#x5FC5;&#x9009;&#xFF0C;&#x7ED3;&#x675F;&#x4F4D;&#x53EF;&#x9009;,&#x5982;&#x679C;&#x4E0D;&#x5199;&#xFF0C;&#x5219;&#x5230;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6700;&#x540E;        </span>
    <span class="hljs-comment">// &#x652F;&#x6301;&#x8D1F;&#x6570;&#xFF08;&#x8868;&#x793A;&#x5012;&#x6570;&#x7B2C;&#x51E0;&#x4F4D;&#xFF09;</span>
    <span class="hljs-keyword">var</span> str2 = <span class="hljs-string">&quot;hello-world&quot;</span>;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;slice&quot;</span>, str2.slice(<span class="hljs-number">1</span>,<span class="hljs-number">-1</span>));

    <span class="hljs-comment">// 3.substr(&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;)&#xFF1A;&#x957F;&#x5EA6;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;substr&#xFF1A;&quot;</span>,str2.substr(<span class="hljs-number">1</span>,<span class="hljs-number">4</span>))

    <span class="hljs-comment">// 4.substring(&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;)&#xFF1A;&#x4E0B;&#x6807;&#x4F4D;&#x7F6E;&#xFF08;&#x4E0D;&#x5305;&#x542B;&#x81EA;&#x5DF1;&#xFF09;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;substring:&quot;</span>,str2.substring(<span class="hljs-number">1</span>,<span class="hljs-number">4</span>))
</code></pre>
<h5 id="3-&#x5B57;&#x7B26;&#x4E32;&#x4F4D;&#x7F6E;&#x65B9;&#x6CD5;-indexof---lastindexof-">3. &#x5B57;&#x7B26;&#x4E32;&#x4F4D;&#x7F6E;&#x65B9;&#x6CD5; indexOf( ) &amp; lastIndexOf( )</h5>
<pre><code class="lang-js">    <span class="hljs-comment">//&#x8FD4;&#x56DE;&#x5B57;&#x7B26;&#x4E32;&#x7247;&#x6BB5;&#x7684;&#x5F00;&#x59CB;&#x4F4D;&#x7F6E;&#x4E0B;&#x6807;&#xFF0C;&#x82E5;&#x4E0D;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;-1</span>
    <span class="hljs-comment">// 1.indexOf &#x53EA;&#x4F1A;&#x8FD4;&#x56DE;&#x7247;&#x6BB5;&#x7B2C;&#x4E00;&#x6B21;&#x51FA;&#x73B0;&#x7684;&#x4F4D;&#x7F6E;&#xFF0C;&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x8868;&#x793A;&#x641C;&#x7D22;&#x7684;&#x8D77;&#x59CB;&#x4F4D;&#x7F6E;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;indexOf&quot;</span>,num1.indexOf(<span class="hljs-string">&quot;l&quot;</span>,<span class="hljs-number">3</span>));
    <span class="hljs-comment">// 2.lastIndexOf &#x8FD4;&#x56DE;&#x6700;&#x540E;&#x4E00;&#x6B21;&#x51FA;&#x73B0;&#x7684;&#x4F4D;&#x7F6E;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;lastIndexOf&quot;</span>,num1.lastIndexOf(<span class="hljs-string">&quot;l&quot;</span>));
</code></pre>
<h5 id="4-trim-">4. trim( )</h5>
<pre><code class="lang-js">    <span class="hljs-comment">// &#x5220;&#x9664;&#x524D;&#x540E;&#x7A7A;&#x683C;</span>
    <span class="hljs-keyword">var</span> str7 = <span class="hljs-string">&quot;   &#x809A;&#x5B50;&#x597D;&#x997F;   &quot;</span>
    <span class="hljs-built_in">console</span>.log(str7.trim().length);
</code></pre>
<h5 id="5-&#x5B57;&#x7B26;&#x4E32;&#x5927;&#x5C0F;&#x5199;&#x8F6C;&#x6362;&#x65B9;&#x6CD5;-touppercase---tolowercase-">5. &#x5B57;&#x7B26;&#x4E32;&#x5927;&#x5C0F;&#x5199;&#x8F6C;&#x6362;&#x65B9;&#x6CD5; toUpperCase( ) &amp; toLowerCase( )</h5>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> str5 = <span class="hljs-string">&quot;hello&quot;</span>;
    <span class="hljs-keyword">var</span> str6 = <span class="hljs-string">&quot;HTML&quot;</span>;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x5927;&#x5199;&quot;</span>,str5.toUpperCase());
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x5C0F;&#x5199;&quot;</span>,str6.toLowerCase());
</code></pre>
<h5 id="6-&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6A21;&#x5F0F;&#x5339;&#x914D;&#x65B9;&#x6CD5;-replace--split--match--search">6. &#x5B57;&#x7B26;&#x4E32;&#x7684;&#x6A21;&#x5F0F;&#x5339;&#x914D;&#x65B9;&#x6CD5; replace() &amp; split() &amp; match() &amp; search()</h5>
<pre><code class="lang-js">    <span class="hljs-comment">// 1.replace()</span>
    <span class="hljs-keyword">var</span> str4 = <span class="hljs-string">&quot;&#x4ECA;&#x5929;&#x662F;&#x661F;&#x671F;&#x5929;&#x5417;&quot;</span>;
    <span class="hljs-built_in">console</span>.log(str4.replace(<span class="hljs-string">&quot;&#x5929;&quot;</span>,<span class="hljs-string">&quot;&#x65E5;&quot;</span>));

    <span class="hljs-comment">// 2.split() &#x5C06;&#x5B57;&#x7B26;&#x4E32;&#x4EE5;&#x67D0;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x4F5C;&#x4E3A;&#x5206;&#x5272;&#x70B9;&#x53BB;&#x5206;&#x5272;&#x4E3A;&#x6570;&#x7EC4;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;slipt&quot;</span>,str2.split(<span class="hljs-string">&quot;-&quot;</span>))
    <span class="hljs-comment">//&#x6570;&#x7EC4;&#x4E4B;&#x95F4;&#x7684;&#x62FC;&#x63A5;</span>
    <span class="hljs-keyword">var</span> arr = [<span class="hljs-string">&quot;hello&quot;</span>, <span class="hljs-string">&quot;world&quot;</span>].concat([<span class="hljs-string">&quot;&#xFF01;&#xFF01;&quot;</span>]);
    <span class="hljs-built_in">console</span>.log(arr)
    <span class="hljs-comment">//&#x5206;&#x5272;&#x5B8C;&#x53D8;&#x6570;&#x7EC4;&#x540E;&#xFF0C;&#x518D;&#x6B21;&#x7EC4;&#x88C5;&#x6210;&#x5B57;&#x7B26;&#x4E32;</span>
    <span class="hljs-keyword">var</span> str3 = <span class="hljs-string">&quot; &quot;</span>;
    <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>;i&lt;arr.length;i++){
        str3 += arr[i]
    }
    <span class="hljs-built_in">console</span>.log(str3);
</code></pre>
<p>&#x7EC3;&#x4E60;&#xFF1A;&#x66FF;&#x6362;&#x6240;&#x6709;&#x7684;&quot;&#x5929;&quot;&#x5B57;</p>
<pre><code class="lang-js">    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">myReplace</span>(<span class="hljs-params">str</span>)</span>{
        <span class="hljs-keyword">for</span>(<span class="hljs-keyword">var</span> i=<span class="hljs-number">0</span>;i&lt;str.length;i++){
            <span class="hljs-keyword">if</span>(str.indexOf(<span class="hljs-string">&quot;&#x5929;&quot;</span>)==<span class="hljs-number">-1</span>){<span class="hljs-comment">//&#x5B57;&#x7B26;&#x4E32;&#x6CA1;&#x6709;&quot;&#x5929;&quot;</span>
                <span class="hljs-built_in">console</span>.log(i+<span class="hljs-string">&quot;&#x6B21;&#x6570;&quot;</span>)
                <span class="hljs-comment">//&#x8DF3;&#x51FA;&#x5FAA;&#x73AF;</span>
                <span class="hljs-keyword">break</span>;
            }
            str = str.replace(<span class="hljs-string">&quot;&#x5929;&quot;</span>,<span class="hljs-string">&quot;&#x65E5;&quot;</span>);
        }
        <span class="hljs-keyword">return</span> str;
    }
    myReplace(str4);

    <span class="hljs-comment">//&#x53EF;&#x7528;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;</span>
    <span class="hljs-built_in">console</span>.log(str4.replace(<span class="hljs-regexp">/&#x5929;/g</span>,<span class="hljs-string">&quot;&#x65E5;&quot;</span>));
</code></pre>
<h5 id="7-localecompare">7. localeCompare()</h5>
<h1 id="array&#x65B9;&#x6CD5;">Array&#x65B9;&#x6CD5;</h1>
<blockquote>
<p>Array&#xFF0C;&#x5176;&#x672C;&#x8EAB;&#x662F;&#x5F15;&#x7528;&#x7C7B;&#x578B;<br>&#x5F3A;&#x8C03;&#x987A;&#x5E8F;&#x7684;&#x6570;&#x636E;&#x96C6;&#x5408;<br>&#x957F;&#x5EA6;&#x548C;&#x4E0B;&#x6807;&#x90FD;&#x662F;&#x7ECF;&#x5E38;&#x548C;&#x6570;&#x7EC4;&#x7ED3;&#x5408;&#x4F7F;&#x7528;<br>&#x4E0B;&#x6807;&#x5176;&#x5B9E;&#x662F;&#x4E2A;&#x6BD4;&#x8F83;&#x7279;&#x6B8A;&#x7684;&#x5C5E;&#x6027;&#x540D;    </p>
</blockquote>
<h3 id="&#x521B;&#x5EFA;&#x6570;&#x7EC4;">&#x521B;&#x5EFA;&#x6570;&#x7EC4;</h3>
<h5 id="1-&#x5B57;&#x9762;&#x91CF;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;">1. &#x5B57;&#x9762;&#x91CF;&#x65B9;&#x5F0F;&#x521B;&#x5EFA;</h5>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> arr1 =[<span class="hljs-number">1</span>,<span class="hljs-string">&quot;string&quot;</span>,{name:<span class="hljs-string">&quot;haha&quot;</span>,age:<span class="hljs-number">18</span>}];
    <span class="hljs-built_in">console</span>.log(arr1.length,arr1[<span class="hljs-number">2</span>].name);

    <span class="hljs-keyword">var</span> obj = {name:<span class="hljs-string">&quot;hehe&quot;</span>,age:<span class="hljs-number">15</span>};
    <span class="hljs-built_in">console</span>.log(obj.name,obj[<span class="hljs-string">&quot;name&quot;</span>],obj.length);

    <span class="hljs-keyword">var</span> arr3 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>];
    <span class="hljs-comment">//&#x4E3B;&#x52A8;&#x8BBE;&#x7F6E;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#xFF0C;&#x6BD4;&#x539F;&#x6765;&#x5927;&#x65F6;&#xFF0C;&#x591A;&#x51FA;&#x7684;&#x662F;undefined&#xFF1B;&#x6BD4;&#x539F;&#x6765;&#x5C11;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x5220;&#x9664;&#x540E;&#x9762;&#x7684;&#x5143;&#x7D20;</span>
    arr3.length = <span class="hljs-number">10</span>;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;arr3&#x7684;&#x957F;&#x5EA6;&quot;</span>,arr3);
    arr3[<span class="hljs-number">2</span>]=<span class="hljs-number">3</span>;<span class="hljs-comment">//&#x8BBE;&#x7F6E;&#x540E;&#x7EED;&#x4E0B;&#x6807;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x589E;&#x52A0;&#x4E86;&#x6570;&#x7EC4;&#x957F;&#x5EA6;</span>
    <span class="hljs-built_in">console</span>.log(arr3);
</code></pre>
<h5 id="2-&#x901A;&#x8FC7;array&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x5B9E;&#x4F8B;">2. &#x901A;&#x8FC7;Array&#x521B;&#x5EFA;&#x6570;&#x7EC4;&#x5B9E;&#x4F8B;</h5>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> arr2 = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Array</span>(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>);
    <span class="hljs-built_in">console</span>.log(arr2);
    <span class="hljs-comment">// new&#x53EF;&#x7701;&#x7565;</span>
    <span class="hljs-keyword">var</span> arr = <span class="hljs-built_in">Array</span>(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>);
</code></pre>
<h3 id="&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;">&#x6570;&#x7EC4;&#x7684;&#x65B9;&#x6CD5;</h3>
<h5 id="1-&#x8F6C;&#x6362;&#x65B9;&#x6CD5;--tolocalestring--tostring--valueof--join">1. &#x8F6C;&#x6362;&#x65B9;&#x6CD5;  toLocaleString() &amp; toString() &amp; valueOf() &amp; join()</h5>
<pre><code class="lang-js">    <span class="hljs-comment">// &#x5C06;&#x6570;&#x7EC4;&#x4EE5;&#x67D0;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x8FDE;&#x63A5;&#x5E76;&#x8F6C;&#x6362;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x9ED8;&#x8BA4;&#x9017;&#x53F7;&#x8FDE;&#x63A5;</span>
    <span class="hljs-keyword">var</span> str1 =<span class="hljs-string">&quot;get-element-by-id&quot;</span>;
    <span class="hljs-comment">// &#x88C1;&#x526A;</span>
    <span class="hljs-keyword">var</span> arr9 =str1.split(<span class="hljs-string">&quot;-&quot;</span>);
    <span class="hljs-built_in">console</span>.log(arr9.join(<span class="hljs-string">&quot;==&quot;</span>));
</code></pre>
<h5 id="2-&#x6808;&#x65B9;&#x6CD5;&#x540E;&#x8FDB;&#x5148;&#x51FA;--push---pop-">2. &#x6808;&#x65B9;&#x6CD5;:&#x540E;&#x8FDB;&#x5148;&#x51FA;  push( ) &amp; pop( )</h5>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> arr4 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];
    <span class="hljs-comment">// 1.push()&#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5C3E;&#x589E;&#x52A0;&#x65B0;&#x5143;&#x7D20;</span>
    arr4.push(<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;push&quot;</span>,arr4);
    <span class="hljs-comment">// 2.pop()&#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5C3E;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span>
    arr4.pop();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;pop&quot;</span>,arr4);
</code></pre>
<h5 id="3-&#x961F;&#x5217;&#x65B9;&#x6CD5;&#x5148;&#x8FDB;&#x5148;&#x51FA;--unshift---shift-">3. &#x961F;&#x5217;&#x65B9;&#x6CD5;:&#x5148;&#x8FDB;&#x5148;&#x51FA;  unshift( ) &amp; shift( )</h5>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> arr4 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];
    <span class="hljs-comment">// 1.unshift()&#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5934;&#x589E;&#x52A0;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span>
    arr4.unshift(<span class="hljs-number">-1</span>,<span class="hljs-number">0</span>);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;unshift&quot;</span>,arr4);
    <span class="hljs-comment">// 2.shift()&#x4F5C;&#x7528;&#x5728;&#x539F;&#x6570;&#x7EC4;&#x4E0A;&#xFF0C;&#x4ECE;&#x961F;&#x5934;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span>
    arr4.shift();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;shift&quot;</span>,arr4);

    <span class="hljs-comment">//&#x5220;&#x9664;&#x961F;&#x5C3E;&#x7684;&#x4E24;&#x4E2A;</span>
    <span class="hljs-built_in">console</span>.log(arr4.length=arr4.length <span class="hljs-number">-2</span>);
    <span class="hljs-comment">//&#x5C01;&#x88C5;  &#x5220;&#x9664;&#x6570;&#x7EC4;&#x961F;&#x5C3E;&#x591A;&#x4E2A;&#x5143;&#x7D20;</span>
    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">popMore</span>(<span class="hljs-params">arr,num</span>)</span>{
        arr.length = arr.length - num;
        <span class="hljs-keyword">return</span> arr;
    }
    <span class="hljs-built_in">console</span>.log(popMore([<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>],<span class="hljs-number">5</span>));
    <span class="hljs-comment">// push&#x548C;unshift&#xFF08;&#x6DFB;&#x52A0;&#xFF09;&#x8FD4;&#x56DE;&#x66F4;&#x65B0;&#x540E;&#x7684;&#x957F;&#x5EA6;</span>
    <span class="hljs-comment">// pop&#x548C;shift&#xFF08;&#x5220;&#x9664;&#xFF09;&#x8FD4;&#x56DE;&#x5220;&#x9664;&#x7684;&#x5143;&#x7D20;</span>
</code></pre>
<h5 id="4-&#x91CD;&#x6392;&#x5E8F;&#x65B9;&#x6CD5;--reverse---sort-">4. &#x91CD;&#x6392;&#x5E8F;&#x65B9;&#x6CD5;  reverse( ) &amp; sort( )</h5>
<pre><code class="lang-js">    <span class="hljs-comment">// 1.reverse()&#x53CD;&#x8F6C;&#x6570;&#x7EC4;</span>
    <span class="hljs-keyword">var</span> arr10 = [<span class="hljs-number">0</span>,<span class="hljs-number">1</span>,<span class="hljs-number">2</span>].reverse();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;reverse&#xFF1A;&quot;</span>,arr10)

    <span class="hljs-comment">// 2.sort()&#x6392;&#x5E8F;  </span>
    <span class="hljs-comment">// &#x5347;&#x5E8F;&#xFF1A;a-b  &#x964D;&#x5E8F;&#xFF1A;b-a</span>
    <span class="hljs-keyword">var</span> arr11 = [<span class="hljs-number">1</span>,<span class="hljs-number">3</span>,<span class="hljs-number">2</span>,<span class="hljs-number">6</span>,<span class="hljs-number">4</span>];
    arr11.sort(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">a,b</span>)</span>{
        <span class="hljs-keyword">return</span> a-b;
    })
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;sort&#xFF1A;&quot;</span>,arr11);

    <span class="hljs-keyword">var</span> arr12 = [<span class="hljs-string">&quot;10&quot;</span>,<span class="hljs-number">3</span>,<span class="hljs-string">&quot;2&quot;</span>,<span class="hljs-number">6</span>,<span class="hljs-number">4</span>];
    arr12.sort();
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;sort:&quot;</span>,arr12);
</code></pre>
<h5 id="5-&#x64CD;&#x4F5C;&#x65B9;&#x6CD5;--concat---slice---splice-">5. &#x64CD;&#x4F5C;&#x65B9;&#x6CD5;  concat( ) &amp; slice( ) &amp; splice( )</h5>
<pre><code class="lang-js">    <span class="hljs-keyword">var</span> arr5 = [<span class="hljs-number">12</span>,<span class="hljs-number">34</span>];
    <span class="hljs-keyword">var</span> arr6 = [<span class="hljs-number">56</span>,<span class="hljs-number">78</span>];
    <span class="hljs-comment">// 1. concat()&#x62FC;&#x63A5;&#x591A;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;</span>
    arr5 = arr5.concat(arr6,[<span class="hljs-number">90</span>,<span class="hljs-number">100</span>]);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;concat&quot;</span>,arr5);

    <span class="hljs-comment">// 2.slice()&#x622A;&#x53D6;&#x6570;&#x7EC4;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;</span>
    <span class="hljs-keyword">var</span> arr8 = [<span class="hljs-string">&quot;a&quot;</span>,<span class="hljs-string">&quot;b&quot;</span>,<span class="hljs-string">&quot;c&quot;</span>,<span class="hljs-string">&quot;d&quot;</span>];
    arr8 = arr8.slice(<span class="hljs-number">1</span>,<span class="hljs-number">3</span>);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;slice:&quot;</span>,arr8);

    <span class="hljs-comment">// 3.splice&#xFF08;start&#xFF0C;length&#xFF0C;newElement&#xFF09;</span>
    <span class="hljs-comment">/**
    * start&#xFF1A;&#x88AB;&#x66FF;&#x4EE3;&#x5143;&#x7D20;&#x7684;&#x5F00;&#x59CB;&#x4E0B;&#x6807;
    * length&#xFF1A;&#x4ECE;start&#x5F00;&#x59CB;&#x6570;&#x7684;&#x957F;&#x5EA6;
    * newElement&#xFF1A;&#x65B0;&#x66FF;&#x4EE3;&#x7684;&#x5143;&#x7D20;
    * &#x66FF;&#x4EE3;&#xFF1A;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x90FD;&#x7ED9;&#xFF0C;&#x957F;&#x5EA6;&#x8BBE;&#x7F6E;1&#xFF0C;&#x66FF;&#x4EE3;&#x5355;&#x4E2A;&#x5143;&#x7D20;&#xFF1A;&#x957F;&#x5EA6;&#x5927;&#x4E8E;1&#xFF0C;&#x5355;&#x4E2A;&#x5143;&#x7D20;&#x66FF;&#x4EE3;&#x591A;&#x4E2A;&#x5143;&#x7D20;&#xFF1A;
    * &#x5220;&#x9664;&#xFF1A;&#x53EA;&#x7ED9;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1B;
    * &#x589E;&#x52A0;&#xFF1A;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#x90FD;&#x7ED9;&#xFF0C;&#x957F;&#x5EA6;&#x8BBE;&#x7F6E;&#x4E3A;0&#xFF1B;
    * &#x8FD4;&#x56DE;&#x503C;&#xFF1A;&#x4EE5;&#x6570;&#x503C;&#x5F62;&#x5F0F;&#x8FD4;&#x56DE;&#x88AB;&#x5220;&#x9664;&#x5143;&#x7D20;
    * */</span>
    <span class="hljs-keyword">var</span> arr7 = [<span class="hljs-string">&quot;a&quot;</span>,<span class="hljs-string">&quot;b&quot;</span>,<span class="hljs-string">&quot;c&quot;</span>,<span class="hljs-string">&quot;d&quot;</span>];
    arr7.splice(<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-string">&quot;A&quot;</span>);
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;splice:&quot;</span>,arr7);
</code></pre>
<h5 id="6-&#x4F4D;&#x7F6E;&#x65B9;&#x6CD5;--indexof---lastindexof-">6. &#x4F4D;&#x7F6E;&#x65B9;&#x6CD5;  indexOf( ) &amp; lastIndexOf( )</h5>
<pre><code class="lang-js">    <span class="hljs-comment">// 1.indexOf&#xFF08;&#x641C;&#x7D22;&#x7684;&#x5143;&#x7D20;&#xFF09;&#x4ECE;&#x5934;&#x90E8;&#x5F00;&#x59CB;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;indexOf&#xFF1A;&quot;</span>,arr14.indexOf(<span class="hljs-string">&quot;1&quot;</span>));
    <span class="hljs-comment">// 2.lastIndexOf&#xFF08;&#x641C;&#x7D22;&#x7684;&#x5143;&#x7D20;&#xFF09;&#x4ECE;&#x5C3E;&#x90E8;&#x5F00;&#x59CB;</span>
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;indexOf&#xFF1A;&quot;</span>,arr14.lastIndexOf(<span class="hljs-number">1</span>));
</code></pre>
<h5 id="7-&#x8FED;&#x4EE3;&#x65B9;&#x6CD5;--every--filter--foreach--map--some">7. &#x8FED;&#x4EE3;&#x65B9;&#x6CD5;  every() &amp; filter() &amp; forEach() &amp; map() &amp; some()</h5>
<table>
<thead>
<tr>
<th style="text-align:left">&#x65B9;&#x6CD5;</th>
<th style="text-align:left">&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">every()</td>
<td style="text-align:left">&#x5BF9;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x8BE5;&#x51FD;&#x6570;&#x5BF9;&#x6BCF;&#x4E00;&#x9879;&#x90FD;&#x8FD4;&#x56DE;true&#xFF0C;&#x5219;&#x8FD4;&#x56DE;true</td>
</tr>
<tr>
<td style="text-align:left">some()</td>
<td style="text-align:left">&#x5BF9;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x8BE5;&#x51FD;&#x6570;&#x5BF9;&#x4EFB;&#x4E00;&#x9879;&#x90FD;&#x8FD4;&#x56DE;true&#xFF0C;&#x5219;&#x8FD4;&#x56DE;true</td>
</tr>
<tr>
<td style="text-align:left">filter()</td>
<td style="text-align:left">&#x5BF9;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#xFF0C;&#x5982;&#x679C;&#x8BE5;&#x51FD;&#x6570;&#x4F1A;&#x8FD4;&#x56DE;true&#x7684;&#x9879;&#x7EC4;&#x6210;&#x7684;&#x6570;&#x7EC4;</td>
</tr>
<tr>
<td style="text-align:left">forEach()</td>
<td style="text-align:left">&#x5BF9;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C;</td>
</tr>
<tr>
<td style="text-align:left">map()</td>
<td style="text-align:left">&#x5BF9;&#x6570;&#x7EC4;&#x4E2D;&#x6BCF;&#x4E00;&#x9879;&#x8FD0;&#x884C;&#x7ED9;&#x5B9A;&#x51FD;&#x6570;&#xFF0C;&#x8FD4;&#x56DE;&#x6BCF;&#x6B21;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x7684;&#x7ED3;&#x679C;&#x7EC4;&#x6210;&#x7684;&#x6570;&#x7EC4;</td>
</tr>
</tbody>
</table>
<pre><code class="lang-js">    <span class="hljs-comment">// 1.every()&#x6BCF;&#x4E00;&#x9879; &amp; some()&#x4EFB;&#x4E00;&#x9879; </span>
    <span class="hljs-keyword">var</span> numbers = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">4</span>,<span class="hljs-number">3</span>,<span class="hljs-number">2</span>,<span class="hljs-number">1</span>]
    <span class="hljs-keyword">var</span> everyResult = numbers.every(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">item,index,array</span>)</span>{
        <span class="hljs-keyword">return</span> (item&gt;<span class="hljs-number">2</span>);
    })
    <span class="hljs-built_in">console</span>.log(everyResult);   <span class="hljs-comment">//false</span>
    <span class="hljs-keyword">var</span> someResult = numbers.some(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">item,index,array</span>)</span>{
        <span class="hljs-keyword">return</span> (item&gt;<span class="hljs-number">2</span>);
    })
    <span class="hljs-built_in">console</span>.log(someResult);   <span class="hljs-comment">//true</span>

    <span class="hljs-comment">// 2.filter() &#x7528;&#x4E8E;&#x8FC7;&#x6EE4;&#x5185;&#x5BB9;&#xFF0C;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x8FD4;&#x56DE;true&#xFF0C;&#x6DFB;&#x52A0;&#x5230;&#x65B0;&#x6570;&#x7EC4;&#xFF1B;&#x8FD4;&#x56DE;false&#xFF0C;&#x5219;&#x4E0D;&#x6DFB;&#x52A0;</span>
    <span class="hljs-keyword">var</span> arr13 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>,<span class="hljs-number">6</span>];
    arr13 = arr13.filter(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">item,index</span>)</span>{
        <span class="hljs-keyword">if</span>(item%<span class="hljs-number">2</span>!==<span class="hljs-number">0</span>){
            <span class="hljs-comment">//&#x6392;&#x9664;&#x5947;&#x6570;</span>
            <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
        }
        <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
    })
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;filter&#xFF1A;&quot;</span>,arr13);

    <span class="hljs-comment">// 3.forEach() &#x904D;&#x5386;&#x6570;&#x7EC4;&#xFF0C;&#x6CA1;&#x6709;&#x8FD4;&#x56DE;&#x503C;&#xFF08;&#x8FD4;&#x56DE;undefined&#xFF09;</span>
    <span class="hljs-keyword">var</span> arr14 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];
    arr14.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">item,index</span>)</span>{
        <span class="hljs-built_in">console</span>.log(item);
        <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
    })
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;arr14&#xFF1A;&quot;</span>,arr14);

    <span class="hljs-comment">// 4.map() &#x904D;&#x5386;&#x6570;&#x7EC4;&#x7684;&#x6BCF;&#x4E2A;&#x5143;&#x7D20;&#x5E76;&#x5904;&#x7406;&#x5143;&#x7D20;&#x7684;&#x503C;&#xFF0C;&#x8FD4;&#x56DE;&#x65B0;&#x6570;&#x7EC4;</span>
    <span class="hljs-keyword">var</span> arr12 = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>];
    arr12 = arr12.map(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">item,index,arr</span>)</span>{
        <span class="hljs-keyword">return</span> item*<span class="hljs-number">2</span>; 
    });
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;map:&quot;</span>,arr12);
</code></pre>
<h5 id="8-&#x5F52;&#x5E76;&#x65B9;&#x6CD5;--reduce--reduceright">8. &#x5F52;&#x5E76;&#x65B9;&#x6CD5;  reduce() &amp; reduceRight()</h5>
<pre><code class="lang-js">    <span class="hljs-comment">// 1.reduce() &#x4ECE;&#x6570;&#x7EC4;&#x7684;&#x7B2C;&#x4E00;&#x9879;&#x5F00;&#x59CB;&#xFF0C;&#x9010;&#x4E2A;&#x904D;&#x5386;&#x5230;&#x6700;&#x540E;</span>
    <span class="hljs-keyword">var</span> vaules = [<span class="hljs-number">1</span>,<span class="hljs-number">2</span>,<span class="hljs-number">3</span>,<span class="hljs-number">4</span>,<span class="hljs-number">5</span>];
    <span class="hljs-keyword">var</span> sum = vaules.reduce(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">prev,cur,index,array</span>)</span>{
        <span class="hljs-keyword">return</span> prev + cur;
    });
    <span class="hljs-built_in">console</span>.log(sum)  <span class="hljs-comment">//15</span>

    <span class="hljs-comment">// 2.reduceRight() &#x4ECE;&#x6570;&#x7EC4;&#x7684;&#x6700;&#x540E;&#x4E00;&#x9879;&#x5F00;&#x59CB;&#xFF0C;&#x5411;&#x524D;&#x904D;&#x5386;&#x5230;&#x7B2C;&#x4E00;&#x9879;</span>
    <span class="hljs-keyword">var</span> sum = vaules.reduceRight(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">prev,cur,index,array</span>)</span>{
        <span class="hljs-keyword">return</span> prev + cur;
    });
    <span class="hljs-built_in">console</span>.log(sum)  <span class="hljs-comment">//15</span>
</code></pre>
<p>&#x7EC3;&#x4E60;&#xFF1A;&#x968F;&#x673A;5&#x4E2A;&#x4E0D;&#x76F8;&#x540C;&#x7684;&#x6570;&#x5B57;&#xFF0C;&#x6570;&#x5B57;&#x8303;&#x56F4;&#x5728;[1~10],&#x5E76;&#x4E14;&#x6DFB;&#x52A0;&#x5230;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;</p>
<pre><code class="lang-js">    <span class="hljs-comment">//&#x968F;&#x673A;&#x6570;&#xFF1A;Math.random() &#x5411;&#x4E0A;&#x53D6;&#x6574;&#xFF1A;Math.ceil()</span>
    <span class="hljs-comment">//&#x5728;[1~10]&#x4E4B;&#x95F4;&#x7684;&#x968F;&#x673A;&#x6570;Math.ceil(Math.random)</span>
    <span class="hljs-keyword">var</span> arr15 =[];
    <span class="hljs-keyword">var</span> num;
    <span class="hljs-keyword">for</span>(i=<span class="hljs-number">0</span>;i&lt;<span class="hljs-number">5</span>;){
        <span class="hljs-built_in">console</span>.count();  <span class="hljs-comment">//&#x63A7;&#x5236;&#x53F0;&#x8BA1;&#x6570;&#x5668;</span>
        <span class="hljs-comment">//5&#x4E2A;&#x968F;&#x673A;&#x6570;</span>
        num = <span class="hljs-built_in">Math</span>.random()*<span class="hljs-number">10</span>;  <span class="hljs-comment">//&#x968F;&#x673A;&#x6570;&#xFF08;0-10&#xFF09;</span>
        num = <span class="hljs-built_in">Math</span>.ceil(num);    <span class="hljs-comment">//&#x968F;&#x673A;&#x6570;[1-10]</span>
        <span class="hljs-keyword">if</span>(arr15.length==<span class="hljs-number">0</span> || arr15.indexOf(num)== <span class="hljs-number">-1</span>){
            <span class="hljs-comment">//length&#x4E3A;0&#xFF0C;&#x5373;&#x6570;&#x7EC4;&#x4E3A;&#x7A7A;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x68C0;&#x67E5;&#x662F;&#x5426;&#x91CD;&#x590D;</span>
            <span class="hljs-comment">//indexOf&#xFF08;&#xFF09;&#x7ED3;&#x679C;&#x4E3A;-1&#xFF0C;&#x5373;&#x6CA1;&#x6709;&#x91CD;&#x590D;&#x7684;&#x5143;&#x7D20;&#xFF08;&#x9664;&#x7B2C;&#x4E00;&#x6B21;&#x5916;&#xFF09;</span>
            arr15.push(num);
            <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x6BCF;&#x6B21;&#xFF1A;&quot;</span>,arr15);
            i++;<span class="hljs-comment">//&#x53EA;&#x6709;&#x6210;&#x529F;&#x6DFB;&#x52A0;&#x7684;&#x6B21;&#x6570;&#x624D;&#x7B97;&#x4E0B;&#x6B21;</span>
        }
    }
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;&#x7EC3;&#x4E60;&#xFF1A;&quot;</span>,arr15);
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Date类型.html" class="navigation navigation-prev " aria-label="Previous page: Date类型">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="date.html" class="navigation navigation-next " aria-label="Next page: 3.3 Date类型">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.2 String & Array","level":"1.5.11","depth":2,"next":{"title":"3.3 Date类型","level":"1.5.12","depth":2,"path":"JS/date.md","ref":"JS/date.md","articles":[]},"previous":{"title":"Date类型","level":"1.5.10","depth":2,"path":"JS/Date类型.md","ref":"JS/Date类型.md","articles":[]},"dir":"ltr"},"config":{"plugins":["toggle-chapters","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"toggle-chapters":{},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"gitbook电子书","gitbook":"*","description":"记录前端相关的知识点以及一些示例的demo"},"file":{"path":"JS/string&array.md","mtime":"2019-03-25T03:37:39.525Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-09-06T08:37:43.293Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

